<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>原生页面跳转</title>
    <style>
      .aNav {
        width: 200px;
        height: 50px;
        background-color: #ccc;
        line-height: 50px;
        text-align: center;
        font-size: 20px;
        font-weight: bold;
      }
      .boxNav {
        width: 500px;
        height: 50px;
        background-color: #ccc;
        line-height: 50px;
        text-align: center;
        font-size: 20px;
        font-weight: bold;
      }
      .newNav {
        width: 500px;
        height: 50px;
        background-color: #ccc;
        line-height: 50px;
        text-align: center;
        font-size: 20px;
        font-weight: bold;
      }
    </style>
  </head>
  <body>
    <div class="nav">
      <div>a链接的方式实现跳转</div>
      <div class="aNav"><a href="http://www.baidu.com">点击跳转到百度</a></div>
      <div>点击事件处理函数实现跳转</div>
      <div class="boxNav">这是一个div盒子，点击跳转到百度</div>
      <div>打开新窗口实现跳转</div>
      <div class="newNav">点击打开新窗口</div>
    </div>
    <script>
      // 原生页面跳转
      const boxNav = document.querySelector(".boxNav");
      boxNav.addEventListener("click", function () {
        window.location.href = "http://www.baidu.com";
      });

      // 打开新窗口
      const newNav = document.querySelector(".newNav");
      newNav.addEventListener("click", function () {
        window.open("http://www.baidu.com");
        //打开新窗口
        // window.open( url, "_blank" )
        //当前页面跳转
        // window.open( url, "_self" )
      });
    </script>
  </body>
</html>
